class Dvisvgm < Formula
  desc "Fast DVI to SVG converter"
  homepage "https://dvisvgm.de"
  url "https://github.com/mgieseki/dvisvgm/releases/download/3.5/dvisvgm-3.5.tar.gz"
  sha256 "41ea2e10fe6bdc4ce7672519cfc2998e5c30c8b29fbcd8901915c7dac7fa494c"
  license "GPL-3.0-or-later"

  bottle do
    sha256 cellar: :any,                 arm64_sequoia: "49dfadfd667f69439a9c75f2baae68145c7c9b3a40d3c9b93e89bea725a45126"
    sha256 cellar: :any,                 arm64_sonoma:  "b7e44c20d83be91e3a1637c6f5ed71799974d4c8aa90d0aead5b26181b7cec47"
    sha256 cellar: :any,                 arm64_ventura: "15665722543df62fb0e593000e78a16c63c2c26f0bc0256f7e31e2b29857e65c"
    sha256 cellar: :any,                 sonoma:        "f59943aa1aed3a13091ba46e2d6de274e591326c5f5e2f70e0dfef05a278de7f"
    sha256 cellar: :any,                 ventura:       "e0891fceaacc7fe276d342d700bab6286a1fe1e42298a81bb7c6598402317a3f"
    sha256 cellar: :any_skip_relocation, arm64_linux:   "b07268ed1e2105fce670746a418acb7604832f963b123acad04f7faae5ffc181"
    sha256 cellar: :any_skip_relocation, x86_64_linux:  "cc45ab10466cf813d4034db865df7d2dcdcb4ec079edcc5b19f21dd478390d69"
  end

  depends_on "autoconf" => :build
  depends_on "automake" => :build
  depends_on "libtool" => :build
  depends_on "pkgconf" => :build

  depends_on "brotli"
  depends_on "freetype"
  depends_on "ghostscript"
  depends_on "potrace"
  depends_on "texlive"
  depends_on "woff2"

  uses_from_macos "zlib"

  def install
    args = [
      "--disable-silent-rules",
      "--with-texlive=#{Formula["texlive"].opt_prefix}",
    ]
    args << "--with-zlib=#{Formula["zlib"].opt_prefix}" if OS.linux?

    system "./configure", *args, *std_configure_args
    system "make"
    system "make", "install"

    pkgshare.install "tests/data/sample.dvi"
  end

  test do
    assert_match version.to_s, shell_output("#{bin}/dvisvgm --version")

    # Convert DVI to SVG
    system bin/"dvisvgm", "--no-fonts", pkgshare/"sample.dvi"
    assert_match "This file was generated by dvisvgm #{version}", (testpath/"sample.svg").read
  end
end
